require("../../@babel/runtime/helpers/Arrayincludes");

var t = require("../../@babel/runtime/helpers/toConsumableArray"), a = getApp().globalData.api;

Page({
    data: {
        loadingExit: !1,
        isUpgrade: !1,
        lastAreaCode: getApp().globalData.selectedCityAreaCode,
        showfilter: !1,
        showfilterindex: null,
        classArray: [],
        screeningArray: [],
        listData: null,
        tagsList: [],
        filterList: [],
        searchValue: "",
        topNum: 0,
        pkgItem: [],
        projectFilter: [],
        projectId: [],
        showMoreItem: !1
    },
    onLoad: function(t) {
        var a = this;
        null != t && t.hasOwnProperty("tag") && (getApp().globalData.jumpPkgList.isJumpPkgList = !0, 
        getApp().globalData.jumpPkgList.requestParamsUrl = t.tag), this.setData({
            searchCity: getApp().globalData.selectedCity
        }), this.loadData(), getApp().globalData.isFirstLoacation && getApp().firstLocation().then(function(t) {
            null != t && (getApp().globalData.isFirstLoacation = !1, t.city != getApp().globalData.selectedCity && a.getCityCode(t.province, t.city, t.latitude, t.longitude));
        }), this.getHeight();
    },
    getHeight: function() {
        var t = this;
        wx.getSystemInfo({
            success: function(a) {
                var e = a.windowHeight;
                t.setData({
                    clientHeight: e
                });
            }
        });
    },
    getCityCode: function(t, e, i, s) {
        var o = this, r = this, l = {
            province: t,
            city: e
        }; 
        a.post1("wechat/home/getlocalcityinfo", l, !1).then(function(t) {
            if ("1" == t.code) {
                var a = t.data.areacode;
                getApp().globalData.localCity = e, getApp().globalData.localCityAreaCode = a, getApp().globalData.localLatitude = i, 
                getApp().globalData.localLongitude = s, getApp().globalData.selectedCity = e, getApp().globalData.selectedCityAreaCode = a, 
                r.setData({
                    searchCity: getApp().globalData.selectedCity
                }), o.loadData();
            }
        }, function(t) {});
    },
    pkgItem: function() {
        var t = this; 
       a.post1("/wechat/home/_findmicropackagelist").then(function(a) {
            console.log(a), t.setData({
                pkgItem: a.values
            });
        });
    },
    loadData: function() {
        this.getRequsetData(1);
    },
    loadMoreData: function() {
        this.data.loadingExit || this.getRequsetData(this.data.listData.pageNum + 1);
    },
    getRequsetData: function(e) {
        var i = this, s = "", o = "";
        0 == i.data.isUpgrade ? 1 == getApp().globalData.jumpPkgList.isJumpPkgList ? (s = getApp().globalData.jumpPkgList.requestParamsUrl, 
        i.setData({
            searchValue: ""
        })) : (i.data.screeningArray.forEach(function(t, a) {
            i.data.filterList.forEach(function(a, e) {
                t.type == a.type && (a.selectId = t.selectId);
            });
        }), i.data.filterList.forEach(function(t, a) {
            0 != t.selectId && t.microCriteriaDTOList.forEach(function(a, e) {
                a.id == t.selectId && ("6C02" == a.type ? o = "st=" + a.code : s += a.code);
            });
        })) : i.setData({
            searchValue: "",
            isUpgrade: !1
        });
        var r = {
            page: e, 
            lat: getApp().globalData.localLatitude || "",
            lon: getApp().globalData.localLongitude || "",
            areacode: getApp().globalData.selectedCityAreaCode,
            selectparam: s,
            orderByUrl: o,
            name:i.data.searchValue     
        };
        a.post1("/wechat/home/_findmicropackagelist", r, !i.data.values).then(function(a) {
       
            if ("SUCCESS" == a.result) {
                var e = i.data.listData;
                console.log(a.values), a.values.list.forEach(function(t) {
                    t.standardItemCategory && (t.standardItemCategory = t.standardItemCategory.split(","));
                }), 1 == a.values.pageNum ? (i.goTop(), e = a.values) : (e.list = [].concat(t(i.data.listData.list), t(a.values.list)), 
                e.pageNum = a.values.pageNum, e.total = a.values.total,
                e.selecttypesdtos = a.values.selecttypesdtos),
                i.setData({
                    loadingExit: e.list.length >= a.values.total,
                    listData: e, 
                    filterList: a.values.selecttypesdtos,
                    values: a.values
                }), 1 == getApp().globalData.jumpPkgList.isJumpPkgList && (getApp().globalData.jumpPkgList.requestParamsUrl = "", 
                getApp().globalData.jumpPkgList.isJumpPkgList = !1), i.checkFilterData();
            }
        }, function(t) {});
    },
    checkFilterData: function() {
        var t = [], a = [], e = 0;
        this.data.filterList.forEach(function(i, s) {
            if (e < 3) {
                var o = {
                    id: 0,
                    code: null,
                    name: "不限",
                    type: i.type,
                    value: null,
                    isShowBottom: !1,
                    orderBy: null,
                    classify: null,
                    showBottomOrderBy: null
                };
                i.microCriteriaDTOList = i.microCriteriaDTOList.filter(function(t) {
                    if (t.isshow) return t;
                }), "6C02" == i.type && (i.typeName = "推荐排序", o.name = "推荐排序");
                var r = i.microCriteriaDTOList;
                0 != r.length && r.unshift(o), 0 != i.selectId && r.forEach(function(t, a) {
                    i.selectId == t.id && (i.selectName = t.name);
                }), "6C02" == i.type ? t.unshift(i) : t.push(i), e += 1;
            } else i.showMore = !1, "6C05" == i.type ? a.unshift(i) : "6C07" != i.type && "districtsel" != i.type || a.push(i);
        });
        var i = this.data.tagsList;
        
        this.data.filterList.forEach(function(t, a) {
            0 != t.selectId && i.forEach(function(a, e) {
                t.selectId == a.id && t.type == a.type && (a.isSelect = 1);
            });
        }), this.setData({
            tagsList: i,
            classArray: t,
            screeningArray: a
        });
    },
    searchTap: function() {
        wx.navigateTo({
            url: "/pages/packagelists/pakage-search/pakage-search"
        });
    },
    setFilterPanel: function(t) {
        this.data;
        var a = t.currentTarget.dataset.findex, e = this.data.showfilterindex, i = this.data.showfilter;
        console.log("0000000000");
        console.log(this.data.showfilter);
        this.setData({
            showfilter: e != a || !i,
            showfilterindex: e == a ? null : a
        });
    },
    itemClassTap: function(t) {
        var a = t.currentTarget.dataset.iteminfo;
        this.hideFilter();
        var e = this.data.filterList;
        e.forEach(function(t, e) {
            t.type == a.type && (t.selectId = a.id);
        }), this.setData({
            filterList: e
        }), this.loadData();
    },
    rightTabMoreTap: function(t) {
        var a = t.currentTarget.dataset.idx, e = this.data.screeningArray;
        "3" == a ? this.setData({
            showMoreItem: !this.data.showMoreItem
        }) : (e.forEach(function(t, e) {
            a == e && (t.showMore = !t.showMore);
        }), this.setData({
            screeningArray: e
        }));
    },
    rightTabMenuItemTap: function(t) {
        var a = t.currentTarget.dataset.iteminfo, e = this.data.screeningArray;
        e.forEach(function(t, e) {
            a.type == t.type && (t.selectId == a.id ? t.selectId = 0 : t.selectId = a.id);
        });
        var i = this.data.projectFilter, s = this.data.projectId;
        i.includes(a.name) ? i = i.filter(function(t) {
            return t != a.name;
        }) : (i.push(a.name), s.push(a.id)), this.setData({
            screeningArray: e,
            projectFilter: i,
            projectId: s
        });
    },
    hideFilter: function() {
        this.setData({
            showfilter: !1,
            showfilterindex: null
        });
    },
    cityListTap: function() {
        wx.navigateTo({
            url: "/pages/city/city-list"
        });
    },
    tagsTap: function(t) {
        var a = t.currentTarget.dataset.taginfo, e = this.data.filterList;
        e.forEach(function(t, e) {
            t.type == a.type && (0 == t.selectId || t.selectId != a.id ? (t.selectId = a.id, 
            console.log(t.selectId, a)) : t.selectId = 0);
        }), this.setData({
            filterList: e
        }), this.loadData();
    },
    cleanTap: function() {
        var t = this.data.screeningArray;
        t.forEach(function(t, a) {
            t.selectId = 0;
        }), this.setData({
            screeningArray: t,
            projectFilter: [],
            projectId: []
        });
    },
    sureTap: function() {
        this.hideFilter(), this.loadData();
    },
    packageDetailTap: function(t) {
        var a = t.currentTarget.dataset.pkginfo, e = "";
        // console.log(111,a);
        e = a.hasOwnProperty("sourceId") ? a.hospital.domain + "-combo-" + a.sourceId : a.hospital.domain + "-combo-n" + a.id, 
        console.log(e, a.hospital), wx.navigateTo({
            url: "/pages/packagedetails/packagedetails?oid=".concat(e, "&areacode=").concat(a.hospital.areacode)+"&hosid="+a.hospital.outdsfid
        });
    },
    goPkgHos: function(t) {
        var a = t.currentTarget.dataset.pkghosinfo.hospital, e = a.domain, i = a.areaCode;
        wx.navigateTo({
            url: "/pages/hospitalinfo/hospitalinfo?domain=".concat(e, "&areaCode=").concat(i)
        });
    },
    upgradeTap: function(t) {
        this.setData({
            isUpgrade: !0,
            searchValue: ""
        }), this.loadData();
    },
    scrollLoading: a.throttle(function(t) {
        t.loadMoreData();
    }, 800),
    onShow: function() {
        this.pkgItem(), this.data.lastAreaCode != getApp().globalData.selectedCityAreaCode && (this.setData({
            searchCity: getApp().globalData.selectedCity,
            lastAreaCode: getApp().globalData.selectedCityAreaCode
        }), this.loadData());
    },
    goTop: function(t) {
        this.setData({
            topNum: 0
        });
    },
    onShareAppMessage: function() {}
});